package org.zj.webview.app;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.solon.annotation.Db;
import org.zj.webview.app.model.Demo;
import org.zj.webview.app.service.DemoService;
import org.noear.solon.annotation.Controller;
import org.noear.solon.annotation.Mapping;
import org.noear.solon.annotation.Param;
import org.noear.solon.core.handle.MethodType;
import org.noear.solon.data.annotation.Tran;

import java.util.List;

@Slf4j
@Controller
public class DemoController {
    @Db("db1")
    private DemoService demoService;

    @Mapping(value = "/dao", method = MethodType.GET)
    public List<Demo> dao() {

      return demoService.list(new QueryWrapper<>());
    }

    @Mapping(value = "/hello", method = MethodType.GET)
    public String hello(@Param(defaultValue = "world") String name) {
        return String.format("Hello %s!", name);
    }

    @Tran
    @Mapping(value = "/tran", method = MethodType.GET)
    public void tran() {
         demoService.test();
    }
}